package Practice07;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Scanner;

public class test3 {

    public void copyFile(String srcFile, String tagFile){
        byte[] b = new byte[100];
        RandomAccessFile rafSrc = null;
        RandomAccessFile rafTag = null;
        try {
            rafSrc = new RandomAccessFile(srcFile,"r");
            rafTag = new RandomAccessFile(tagFile,"rw");
            rafSrc.read(b);
            rafTag.write(b);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (rafSrc != null) {
                    rafSrc.close();
                }
                if (rafTag != null) {
                    rafTag.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入被复制的文件的地址：");
        String src = sc.nextLine();
        System.out.println("请输入目标文件的地址：");
        String tag = sc.nextLine();

        new test3().copyFile(src,tag);
        System.out.println("复制完成,复制后的大小是byte数组的大小");

    }
}
